package com.donleo.mybatis.controller;

import com.donleo.mybatis.common.CommonResult;
import com.donleo.mybatis.model.Role;
import com.donleo.mybatis.service.IRoleService;
import io.swagger.annotations.ApiOperation;
import org.springframework.util.Assert;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * @author liangd
 * date 2020-12-04 17:41
 * code 角色控制层
 */
@RestController
@RequestMapping("/role")
public class RoleController {

    @Resource
    private IRoleService roleService;


    @PostMapping("/add")
    public CommonResult add(@RequestBody Role role) {
        return roleService.add(role);
    }

    @DeleteMapping("/delete")
    public CommonResult delete(Integer id) {
        Integer count = roleService.delete(id);
        return CommonResult.success(count);
    }

    @PutMapping("/update")
    public CommonResult update(@RequestBody Role role) {
        Assert.notNull(role.getId(),"Id is not null");
        Integer count = roleService.update(role);
        return CommonResult.success(count);
    }

    @GetMapping("/findById")
    public CommonResult findById1(@RequestParam Integer id) {
        Role role = roleService.findById(id);
        return CommonResult.success(role);
    }

    @GetMapping("/findAll")
    public CommonResult findAll() {
        return roleService.findAllRole();
    }
}
